---
sidebar_position: 3
title: Querying a SQL DB
hide_table_of_contents: true
---

# Querying a SQL DB

We can replicate our SQLDatabaseChain with Runnables.

## Setup

We'll need the Chinook sample DB for this example.

First install `typeorm`:

```bash npm2yarn
npm install typeorm
```

Then install the dependencies needed for your database. For example, for SQLite:

```bash npm2yarn
npm install sqlite3
```

For other databases see https://typeorm.io/#installation.

Finally follow the instructions on https://database.guide/2-sample-databases-sqlite/ to get the sample database for this example.

## Composition

import CodeBlock from "@theme/CodeBlock";
import SQLDBExample from "@examples/guides/expression_language/cookbook_sql_db.ts";

import IntegrationInstallTooltip from "@mdx_components/integration_install_tooltip.mdx";

<IntegrationInstallTooltip></IntegrationInstallTooltip>

```bash npm2yarn
npm install @langchain/openai
```

<CodeBlock language="typescript">{SQLDBExample}</CodeBlock>
